package httpservice
{
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.http.HTTPService;

	public class BaseHttpService 
	{
		public function BaseHttpService()
		{
			
		}
		
		protected function request( requestUrl:String, method:String, onResult:Function, 
									parameters:Object = null ):void  {	
			var httpService:HTTPService = new HTTPService();
			httpService.url = Constants.serviceUrl + requestUrl;
			httpService.addEventListener(ResultEvent.RESULT, onResult);
			httpService.addEventListener(FaultEvent.FAULT, onFault);
			httpService.method = method;
			httpService.resultFormat = HTTPService.RESULT_FORMAT_E4X;
			if( parameters == null ) {
				httpService.send();
			}
			else {
				httpService.send( parameters );
			}
		}
		
		protected function onFault(event:FaultEvent):void  {
			trace( "http service failed " + event.fault );
		}
		
	}
}